package cn.dt70.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class GetCode {

    public static String getSerialNumber(int length) {
        int hashCodeV = UUID.randomUUID().toString().hashCode();
        if (hashCodeV < 0) {// 有可能是负数
            hashCodeV = -hashCodeV;
        }

        StringBuffer sbf = new StringBuffer();
        sbf.append(hashCodeV);

        return sbf.substring(0,length);
    }

    public static String getSerialDateCode() {

        Date date= new Date();
        SimpleDateFormat smt= new SimpleDateFormat("yyyyMMddHH");
        StringBuffer sbf= new StringBuffer(smt.format(date));

        sbf.append(getSerialNumber(4));
        System.out.println(sbf.toString());

        return sbf.toString();
    }

}
